package com.wh.blog.service;

import com.wh.blog.mapper.BlogMapper;
import com.wh.blog.model.BlogInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BlogService {
    @Autowired
    BlogMapper blogMapper;

    public List<BlogInfo> getBlogList() {
        List<BlogInfo> blogList = blogMapper.getBlogList();
        for (BlogInfo blog : blogList) {
            String content = blog.getContent();
            if(content.length()>50){
                blog.setContent(content.substring(0, 50));
            }
        }
        return blogList;
    }

    public BlogInfo selectById(Integer BlogId) {
        return blogMapper.selectById(BlogId);

    }

    public Integer updateBlog(BlogInfo blogInfo) {
        return blogMapper.updateBlog(blogInfo);
    }

    public  Integer deleteByBlogId(Integer blogId) {
        BlogInfo blogInfo = new BlogInfo();
        blogInfo.setId(blogId);
        blogInfo.setDeleteFlag(1);
        return blogMapper.updateBlog(blogInfo);
    }

    public Integer addBlog(BlogInfo blogInfo) {
        return blogMapper.addBlog(blogInfo);
    }
}
